package com.zjdiepu.www.rest.api.base;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.commpent.handler.TokenUserHelper;
import com.zjdiepu.www.ibiz.third.IJuheAreaService;
import com.zjdiepu.www.ibiz.third.IJuheCityService;
import com.zjdiepu.www.ibiz.third.IJuheProvinceService;
import com.zjdiepu.www.model.third.dto.JuheArea;
import com.zjdiepu.www.model.third.dto.JuheCity;
import com.zjdiepu.www.model.third.dto.JuheProvince;
import com.zjdiepu.www.model.third.ext.JuheAreaExt;
import com.zjdiepu.www.model.third.ext.JuheCityExt;
import com.zjdiepu.www.model.third.ext.JuheProvinceExt;
@RestController
@RequestMapping(value= "AreaController", produces="application/json;charset=UTF-8", method = RequestMethod.POST)
@Api(tags = {"地区查询"}, produces="application/json;charset=UTF-8")
public class AreaController extends BaseController{

	@Resource
	private IJuheProvinceService juheProvinceService;
	
	@Resource
	private IJuheCityService juheCityService;
	
	@Resource
	private IJuheAreaService juheAreaService;
	
	@Resource
    private TokenUserHelper tokenUserHelper;
	
	
	 @ApiOperation(value = "获取所有省份", response = ApiResponse.class, httpMethod="POST")
	    @ApiImplicitParams({ //还款状态、当前逾期金额
	    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
	    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String")
	    })
	    @RequestMapping(value = "getAllProvince")
	public ApiResponse getAllProvince(){
		 tokenUserHelper.getUser();
		JuheProvinceExt juheProvinceExt=new JuheProvinceExt();
		juheProvinceExt.setBaseWhere();
		juheProvinceExt.withOutPage();
		List<JuheProvince> list=juheProvinceService.selectByExt(juheProvinceExt);
		if(list!=null && list.size()>0){
			return ApiResponse.success(list);
		}
		return ApiResponse.success(false);
	}
	
	 @ApiOperation(value = "根据省id获取地区数据", response = ApiResponse.class, httpMethod="POST")
    @ApiImplicitParams({ 
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "getCityByProvinceId")
	public ApiResponse getCityByProvinceId(@RequestBody JuheCityExt juheCityExt){
		 tokenUserHelper.getUser();
		juheCityExt.setBaseWhere();
		juheCityExt.withOutPage();
		List<JuheCity> list=juheCityService.selectByExt(juheCityExt);
		if(list!=null && list.size()>0){
			return ApiResponse.success(list);
		}
		return ApiResponse.success(false);
	}
	
	 @ApiOperation(value = "根据省id获取地区数据", response = ApiResponse.class, httpMethod="POST")
    @ApiImplicitParams({ 
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "getAreaByCityId")
	public ApiResponse getAreaByCityId(@RequestBody JuheAreaExt juheAreaExt){
		 tokenUserHelper.getUser();
		juheAreaExt.setBaseWhere();
		juheAreaExt.withOutPage();
		List<JuheArea> list=juheAreaService.selectByExt(juheAreaExt);
		if(list!=null && list.size()>0){
			JuheArea juheArea=new JuheArea();
//			juheArea.setAreaCode("000000");
			juheArea.setAreaId("000000");
			juheArea.setAreaName("未知地区");
			list.add(juheArea);
			return ApiResponse.success(list);
		}
		return ApiResponse.success(false);
	}
}
